package com.smashcrush.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Script implements Serializable, SecureObject {

	@Id
	@Column(columnDefinition = "CHAR (36)", nullable = false)
	String id;

	@Column(columnDefinition = "CHAR (36)", nullable = false)
	String userId;

	String name;

	@Column(columnDefinition = "VARCHAR(2048)")
	String description;

	ScriptSourceType scriptSourceType;

	BrowserType browserType;

	@Column(columnDefinition = "TEXT")
	String source;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public BrowserType getBrowserType() {
		return browserType;
	}

	public void setBrowserType(BrowserType browserType) {
		this.browserType = browserType;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public ScriptSourceType getScriptSourceType() {
		return scriptSourceType;
	}

	public void setScriptSourceType(ScriptSourceType scriptSourceType) {
		this.scriptSourceType = scriptSourceType;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public Map<String, String> validate() {
		Map<String, String> errors = new HashMap<String, String>();

		if (name == null || name.trim().equals("")) {
			errors.put("name", "Name is empty");
		}

		if (source == null || source.trim().equals("")) {
			errors.put("source", "Source is empty");
		}

		return errors;
	}

}
